package cd.cdyb.sms.controller.base;


/**
 * @author Kang
 * @description 用户控制层返回json数据的包装类
 */
public class JsonResult {
    private Integer ret;

    private String msgId;
    private String msg;
    private Integer code;
    private Integer recordsTotal;
    private Object data;

    private Integer money;

    private Integer num;

    private JsonResult() {

    }

    public Integer getRet() {
        return ret;
    }

    public void setRet(Integer ret) {
        this.ret = ret;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public static JsonResult ok() {
        return ok(null, null);
    }

    /**
     * 提供返回数据成功时的方法
     *
     * @param data
     * @return
     */
    public static JsonResult ok(Object data) {
        return ok(data, null);
    }

    public static JsonResult ok(Object data, Integer total) {
        JsonResult rs = new JsonResult();
        rs.ret = 1;
        rs.data = data;
        rs.recordsTotal = total;

        if (rs.getData() == null) {
            rs.setData(new Object());
        }
        return rs;
    }

    /**
     * 提供返回数据出现异常信息的方法
     *
     * @param msgId
     * @return
     */
    public static JsonResult fail(String msgId, Integer code, String msg) {
        JsonResult rs = new JsonResult();
        rs.ret = 0;
        rs.msgId = msgId;
        rs.msg = msg;
        rs.code = code;
        return rs;
    }

    public String getMsgId() {
        return msgId;
    }

    public void setMsgId(String msgId) {
        this.msgId = msgId;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Integer getRecordsTotal() {
        return recordsTotal;
    }

    public void setRecordsTotal(Integer recordsTotal) {
        this.recordsTotal = recordsTotal;
    }

    public Integer getCode() {
        return code;
    }

    public Integer getMoney() {
        return money;
    }

    public void setMoney(Integer money) {
        this.money = money;
    }

    public Integer getNum() {
        return num;
    }

    public void setNum(Integer num) {
        this.num = num;
    }

    public static JsonResult ok(Object data, Integer total, Integer money, Integer num) {
        JsonResult rs = new JsonResult();
        rs.ret = 1;
        rs.data = data;
        rs.recordsTotal = total;
        if (money == null) {
            money = 0;
        }
        rs.money = money;
        rs.num = num;
        if (rs.getData() == null) {
            rs.setData(new Object());
        }

        return rs;
    }
}
